package com.findviewbydream.evil.eda.Utils.SuperToast;

import android.app.Activity;

import com.github.johnpersano.supertoasts.SuperCardToast;
import com.github.johnpersano.supertoasts.SuperToast;
import com.github.johnpersano.supertoasts.util.OnClickWrapper;
import com.github.johnpersano.supertoasts.util.OnDismissWrapper;

/********************************************
 * 工程名：HelloYouth
 * 包名：com.findviewbydream.evil.helloyouth.Utils.SuperToast
 * 时间：16-6-9 下午8:19
 * 作者：白雨濃 evil
 * 邮箱：evilbai@foxmail.com
 * 内容：超级提示窗（进度条） 工具类
 * 注意：布局内应有
 * <LinearLayout
 * android:id="@+id/card_container"
 * android:layout_width="match_parent"
 * android:layout_height="wrap_content"
 * android:orientation="vertical"/>
 ********************************************/
public class ProgressToast
{
    private SuperCardToast superCardToast;

    private Activity activity;

    private String text = "";
    private boolean swipeDismiss = true;
    private int progress = 0;
    private int maxProgress = 100;

    private Duration duration = Duration.NORMAL;
    private Background background = Background.GREEN;
    private Animations animations = Animations.FLYIN;

    public ProgressToast(Activity activity)
    {
        this.activity = activity;
        superCardToast = new SuperCardToast(activity, SuperToast.Type.PROGRESS_HORIZONTAL);
    }


    public ProgressToast show()
    {
        superCardToast.setText(text);
        superCardToast.setSwipeToDismiss(swipeDismiss);
        superCardToast.setMaxProgress(maxProgress);

        switchDuration();
        switchBackground();
        switchAnimations();

        superCardToast.show();
        return this;
    }

    /**
     * 按钮点击事件
     *
     * @param onClick
     * @return
     */
    public ProgressToast setOnClick(OnClick onClick)
    {
        superCardToast.setOnClickWrapper(
                new OnClickWrapper(activity + "", onClick));
        return this;
    }

    /**
     * 触摸消失事件
     *
     * @param touchDismissClick
     * @return
     */
    public ProgressToast setTouchDismissClick(TouchDismissClick touchDismissClick)
    {
        superCardToast.setOnDismissWrapper(
                new OnDismissWrapper(activity + "", touchDismissClick));
        return this;
    }

    public enum Duration
    {
        MAX, LONG, SHORT, NORMAL
    }

    public enum Background
    {
        BLACK, BLUE, GRAY, GREEN, ORANGE, PURPLE, RED, WHITE
    }

    public enum Animations
    {
        FADE, FLYIN, SCALE, POPUP
    }


    private void switchDuration()
    {
        switch (duration)
        {
            case NORMAL:
                superCardToast.setDuration(2000);
                break;
            case SHORT:
                superCardToast.setDuration(1000);
                break;
            case LONG:
                superCardToast.setDuration(5000);
                break;
            case MAX:
                superCardToast.setDuration(Integer.MAX_VALUE);
                break;
        }

    }

    private void switchBackground()
    {
        switch (background)
        {
            case BLACK:
                superCardToast.setBackground(SuperToast.Background.BLACK);
                break;
            case GRAY:
                superCardToast.setBackground(SuperToast.Background.GRAY);
                break;
            case BLUE:
                superCardToast.setBackground(SuperToast.Background.BLUE);
                break;
            case GREEN:
                superCardToast.setBackground(SuperToast.Background.GREEN);
                break;
            case ORANGE:
                superCardToast.setBackground(SuperToast.Background.ORANGE);
                break;
            case PURPLE:
                superCardToast.setBackground(SuperToast.Background.PURPLE);
                break;
            case RED:
                superCardToast.setBackground(SuperToast.Background.RED);
                break;
            case WHITE:
                superCardToast.setBackground(SuperToast.Background.WHITE);
                break;
        }
    }

    private void switchAnimations()
    {
        switch (animations)
        {
            case FADE:
                superCardToast.setAnimations(com.github.johnpersano.supertoasts.SuperToast.Animations.FADE);
                break;
            case FLYIN:
                superCardToast.setAnimations(com.github.johnpersano.supertoasts.SuperToast.Animations.FLYIN);
                break;
            case POPUP:
                superCardToast.setAnimations(com.github.johnpersano.supertoasts.SuperToast.Animations.POPUP);
                break;
            case SCALE:
                superCardToast.setAnimations(com.github.johnpersano.supertoasts.SuperToast.Animations.SCALE);
                break;
        }
    }

    public ProgressToast setText(String text)
    {
        this.text = text;
        return this;
    }

    public ProgressToast setProgress(int progress)
    {
        superCardToast.setProgress(progress);
        return this;
    }

    public ProgressToast setMaxProgress(int maxProgress)
    {
        this.maxProgress = maxProgress;
        return this;
    }

    public ProgressToast setDuration(Duration duration)
    {
        this.duration = duration;
        return this;
    }

    public ProgressToast setBackgroundColor(Background background)
    {
        this.background = background;
        return this;
    }

    public ProgressToast setAnimations(Animations animations)
    {
        this.animations = animations;
        return this;
    }

    public ProgressToast setSwipeToDismiss(boolean swipeDismiss)
    {
        this.swipeDismiss = swipeDismiss;
        return this;
    }


}
